package com.xmy.cultivate.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

//@Configuration
public class FeignConfig implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        /*if (attributes == null){
            requestTemplate.header("X-Token", "454211212");
            return;
        }*/
        HttpServletRequest request = attributes.getRequest();
        String id = request.getHeader("X-Token");
        if (id==null){
            return;
        }
        //System.out.println("token"+id);
        requestTemplate.header("X-Token", request.getHeader("X-Token"));
    }

}